﻿
@using Entidades.Sistema.Venta
@using System.Collections.ObjectModel;

@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();

    var grid = Html.DevExpress().GridView(
        settings =>
        {
            settings.Name = "gvEditingc";
            settings.KeyFieldName = "IdContacto";
            settings.CallbackRouteValues = new { Controller = "Contacto", Action = "EditContactoPartial",nrocliente = ViewBag.IdCliente }; 
            settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Contacto", Action = "EditContactoAddNewPartial", nrocliente = ViewBag.IdCliente };
            settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Contacto", Action = "EditContactoUpdatePartial", nrocliente = ViewBag.IdCliente };
            settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Contacto", Action = "EditContactoDeletePartial", nrocliente = ViewBag.IdCliente }; 
            settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;

            settings.SettingsBehavior.ConfirmDelete = true;
            settings.SettingsPopup.EditForm.Width = 600;
            settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.Center;
            settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
            settings.SettingsPager.FirstPageButton.Visible = true;
            settings.SettingsPager.LastPageButton.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };


            settings.Settings.ShowFilterRow = true;
            settings.Settings.ShowFilterRowMenu = true;
            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowClearFilterButton = true;

            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            settings.CommandColumn.Visible = true;
            //settings.CommandColumn.ShowNewButtonInHeader = ViewBag.PermisoCreate;
            //settings.CommandColumn.ShowEditButton = ViewBag.PermisoEdit;
            //settings.CommandColumn.ShowDeleteButton = ViewBag.PermisoDelete;


            settings.CommandColumn.ShowNewButtonInHeader = true;
            settings.CommandColumn.ShowEditButton = true;
            settings.CommandColumn.ShowDeleteButton = true;           
            
            
            
            settings.SettingsBehavior.ConfirmDelete = true;
            settings.SettingsPopup.EditForm.Width = 600;
            settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.Center;
            settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
            settings.SettingsPager.FirstPageButton.Visible = true;
            settings.SettingsPager.LastPageButton.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };
            
            
            settings.Settings.ShowFilterRow = true;
            settings.Settings.ShowFilterRowMenu = true;
            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowClearFilterButton = true;
            
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            //settings.CommandColumn.Visible = true;
            //settings.CommandColumn.ShowNewButtonInHeader = ViewBag.PermisoCreate;
            //settings.CommandColumn.ShowEditButton = ViewBag.PermisoEdit;
            //settings.CommandColumn.ShowDeleteButton = ViewBag.PermisoDelete;


            settings.Columns.Add("Apellido");
            settings.Columns.Add("Nombre");
            settings.Columns.Add("Email");
            settings.Columns.Add("Telefono");
            settings.Columns.Add("Celular");           

            settings.Columns.Add(
                 column =>
                 {
                     column.FieldName = "Cliente.IdCliente";
                     column.Caption = "Nombre Cliente";

                     column.ColumnType = MVCxGridViewColumnType.ComboBox;
                     var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                     comboBoxProperties.DataSource = ViewBag.Cliente;
                     comboBoxProperties.TextField = "Nombre";
                     comboBoxProperties.ValueField = "IdCliente";
                     comboBoxProperties.ValueType = typeof(int);
                     comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;
                     comboBoxProperties.ValidationSettings.CausesValidation = false;
                 });
            
        });

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()




